﻿using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Windows.Input;
using Vtron.HipcConfigurationTools.Core;

namespace Vtron.HipcConfigurationTools
{
    public class DecodeListViewModel : INotifyPropertyChanged
    {
        private ICommand removeCodecCommand;
        public DecodeListViewModel()
        {
            CodecInfoes = new ObservableCollection<CodecInfo>();
            removeCodecCommand = new DelegateCommand<CodecInfo>(RemoveCodec);
        }

        public string HeaderInfo { get; set; }

        public ObservableCollection<CodecInfo> CodecInfoes { get; private set; }

        public ICommand RemoveCodecCommand { get { return removeCodecCommand; } }

        private void RemoveCodec(CodecInfo obj)
        {
            CodecInfoes.Remove(obj);

            MainWindow mainWindow = App.Current.Windows[0] as MainWindow;
            mainWindow.SaveCodec();
        }

        private CodecInfo currentCodecItem;

        public CodecInfo CurrentCodecItem
        {
            get { return currentCodecItem; }
            set
            {
                currentCodecItem = value;

                if (PropertyChanged != null)
                {
                    PropertyChanged.Invoke(this, new PropertyChangedEventArgs("CurrentCodecItem"));
                }

                if (currentCodecItem != null)
                {
                    Utils.IP = currentCodecItem.Ip;

                    MainWindow mainWindow = App.Current.Windows[0] as MainWindow;
                    DecodeView view = new DecodeView();
                    view.DataContext = new DecodeViewModel();
                    mainWindow.researchControl.Items.Clear();
                    mainWindow.researchControl.Items.Add(view);
                }
            }
        }

        public void Selected()
        {
            //MainWindow mainWindow = App.Current.Windows[0] as MainWindow;
            //EncodedView view = new EncodedView();
            //view.DataContext = new EncodedViewModel();
            //mainWindow.ActionContent.Content = view;
            //mainWindow.CodecTitle.Text = currentCodecItem.Ip;

            //Storyboard outTransition = mainWindow.Resources["OutTransition"] as Storyboard;
            //outTransition.Begin();
        }

        public event PropertyChangedEventHandler PropertyChanged;
    }
}